Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report collected results #9

Merged
merged 8 commits into from
Mar 18, 2023
Merged

Report collected results #9

merged 8 commits into from
Mar 18, 2023

Conversation

kaiosilveira
Copy link
Owner

@kaiosilveira kaiosilveira commented Mar 18, 2023

Chapter 21: Counting

Our goal is this chapter was to collect a summary of the test execution. We accomplish that by implementing a TestResult class that will be responsible for holding these results and displaying then when requested.

Implementation checklist:

Invoke tearDown afterward
☑️ Invoke tearDown even if the test method fails
☑️ Run multiple tests
Report collected results
Log string in WasRun

Closes #7

This change will enable us to display a visual report of the tests being run, so we can give feedback to users (instead of the program just blankly finishing)

Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results 👈🏼

---

Output:
➜ python3 src/test_case_test.py
Traceback (most recent call last):
  File "tdd-xunit-example/src/test_case_test.py", line 12, in <module>
    TestCaseTest("testTemplateMethod").run()
  File "tdd-xunit-example/src/test_case.py", line 12, in run
    method()
  File "tdd-xunit-example/src/test_case_test.py", line 9, in testTemplateMethod
    assert ("1 run, 0 failed" == result.summary())
                                 ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'summary'
This class will be used to hold a summary of the test suite execution. For now, though, it's just implementing a summary method with a hardcoded implementation.

Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results 👈🏼

---

Output:
➜ python3 src/test_case_test.py
Traceback (most recent call last):
  File "tdd-xunit-example/src/test_case_test.py", line 12, in <module>
    TestCaseTest("testTemplateMethod").run()
  File "tdd-xunit-example/src/test_case.py", line 12, in run
    method()
  File "tdd-xunit-example/src/test_case_test.py", line 9, in testTemplateMethod
    assert ("1 run, 0 failed" == result.summary())
                                 ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'summary'
Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results 👈🏼
This instance variable will be used to hold the number of tests there were ran in a test session. For now, though, it is hardcoded to the value 1.

Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results 👈🏼
This method will be responsible for updating the value of runCount everytime a test is executed

Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results 👈🏼

---

Output:
➜ python3 src/test_case_test.py
Traceback (most recent call last):
  File "tdd-xunit-example/src/test_case_test.py", line 12, in <module>
    TestCaseTest("testTemplateMethod").run()
  File "tdd-xunit-example/src/test_case.py", line 15, in run
    method()
  File "tdd-xunit-example/src/test_case_test.py", line 9, in testTemplateMethod
    assert ("1 run, 0 failed" == result.summary())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
This call is needed so we can increment the runCount variable and compute the number of tests ran in a session

Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results 👈🏼
Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results 👈🏼

---

Output:
➜ python3 src/test_case_test.py
Traceback (most recent call last):
  File "tdd-xunit-example/src/test_case_test.py", line 18, in <module>
    TestCaseTest("testFailedResult").run()
  File "tdd-xunit-example/src/test_case.py", line 17, in run
    method()
  File "tdd-xunit-example/src/test_case_test.py", line 13, in testFailedResult
    result = test.run()
             ^^^^^^^^^^
  File "tdd-xunit-example/src/test_case.py", line 16, in run
    method = getattr(self, self.name)
             ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WasRun' object has no attribute 'testBrokenMethod'
This implementation will support the code being executed as part of TestCase.testFailedResult. For now, though, we're just raising an exception.

Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results ✅

---

Output:
➜ python3 src/test_case_test.py
Traceback (most recent call last):
  File "tdd-xunit-example/src/test_case_test.py", line 18, in <module>
    TestCaseTest("testFailedResult").run()
  File "tdd-xunit-example/src/test_case.py", line 17, in run
    method()
  File "tdd-xunit-example/src/test_case_test.py", line 13, in testFailedResult
    result = test.run()
             ^^^^^^^^^^
  File "tdd-xunit-example/src/test_case.py", line 17, in run
    method()
  File "tdd-xunit-example/src/was_run.py", line 20, in testBrokenMethod
    raise Exception
Exception
@kaiosilveira kaiosilveira marked this pull request as ready for review March 18, 2023 15:09
@kaiosilveira kaiosilveira merged commit c5ffa61 into main Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chapter 21: Counting
1 participant